function lengthOfLongestSubstring(s) {
    if (s.length <= 1) return s.length;

    let m = new Map();
    let maxLen = 0;

    for (let start=0, end=0; end<s.length; end++) {
        if (m.has(s[end])) {
            start = Math.max(start, m.get(s[end]) + 1);
        };

        m.set(s[end], end);
        maxLen = Math.max(maxLen, end - start + 1);
    };

    return maxLen;
};